home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7201 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: free1-slip207.tele.queensu.ca!user
  2. From: 3gl21@qlink.queensu.ca (Gregory Lo)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Getting functions out of libraries to work
  5. Date: Wed, 21 Feb 1996 20:45:51 -0608
  6. Organization: Queen's University
  7. Message-ID: <3gl21-2102962045510001@free1-slip207.tele.queensu.ca>
  8. References: <312BBC29.6772@uni.massey.ac.nz>
  9. Reply-To: 3gl21@qlink.queensu.ca
  10. NNTP-Posting-Host: free1-slip207.tele.queensu.ca
  11. X-Newsreader: Yet Another NewsWatcher 2.2.0b4
  12.  
  13. In article <312BBC29.6772@uni.massey.ac.nz>, Nigel.Ramsay.1@massey.ac.nz wrote:
  14.  
  15. > I am trying to get some functions out of a library to work. The problem 
  16. > is that I keep getting an "unresolved external" error whenever I try to 
  17. > call the functions.
  18. > The funny thing is that it works fine when I compile under just C.
  19.  
  20. The functions in the library were compiled in C, with "C" linkage.
  21.  
  22. Your C++ compiler will mangle the names of all the identifiers.  To
  23. prevent this, surround the prototypes of the C functions you're trying to
  24. access with 'extern "C" {' and '}'
  25.  
  26. You could go into the header file and manually change add these lines, or
  27. you could use them before you #include the appropriate header file.
  28.  
  29. Many companies that produce C libs or publish headers for C APIs, usually
  30. put these statements in the actual header file with #if statements that
  31. check for a C++ compiler.  The resulting header file will work correctly
  32. when accessed from either a C compiler or from a C++ compiler.
  33. Greg Lo
  34.